package view
{
	import laya.display.Sprite;
	import laya.ui.Image;
	import laya.maths.Point;
	/**
	 * ...
	 * @author
	 */
	public class Bulle extends Sprite{
		private var img:Sprite;
		private var type:int;
		public var attack:int;
		public var hitRadius:Point;
		public function Bulle(){
			img = new Sprite();
			this.addChild(img);
			hitRadius = new Point(9,21);
			GameDispatcher.getInstance().on(EventName.GAME_PAUSE,this,onPause);
			GameDispatcher.getInstance().on(EventName.GAME_RESUME,this,onResume);
		}

		/**
		 * 子弹类型（1普通2强力）
		 */
		public function init(x:int,y:int,type:int,attack:int):void
		{
			img.loadImage("gameRole/bullet2.png");
			this.x = x - this.img.width/2;
			this.y = y - 50;
			this.attack = attack;
			LayerManager.roleLayer.addChild(this);
			startMove();
		}

		private function startMove():void
		{
			Laya.timer.frameLoop(1,this,moveUp);
		}

		private function moveUp():void
		{
			this.y -= GameManager.bulleSpeed;
			if(this.y < -20)
			{
				Laya.timer.clear(this,moveUp);
				this.removeSelf();
			}
		}

		public function hit():void
		{
			Laya.timer.clear(this,moveUp);
			this.removeSelf();
		}

		private function onPause():void
		{
			Laya.timer.clear(this,moveUp);
		}

		private function onResume():void
		{
			startMove();
		}
	}

}